package com.aidl.demo.ui.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import java.util.List;

/**
 * Created by Administrator on 2018/4/9 0009.
 */

public class MyViewPagerAdapter extends PagerAdapter {

    private List<GridView> gridViews;
    private Context context;

    public MyViewPagerAdapter(List<GridView> gridViews, Context context) {
        this.gridViews = gridViews;
        this.context = context;
    }

    @Override
    public int getCount() {
        return gridViews.size() == 0 ? null : gridViews.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        container.addView(gridViews.get(position));
        return gridViews.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(gridViews.get(position));
    }
}
